<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>swiper-动态</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/VUE/swiper/swiper-bundle.min.css">
    <script src="/VUE/swiper/swiper-bundle.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .swiper {
            width: 1400px;
            height: 355px;
            margin: 20px auto;
            box-sizing: border-box;
            overflow: hidden;
        }

        .swiper img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<header>导航栏</header>

<div class="swiper">
    <div class="swiper-wrapper">
<!--        <div class="swiper-slide"><img src="/images/01.jpg" alt=""></div>-->
<!--        <div class="swiper-slide"><img src="/images/02.jpg" alt=""></div>-->
<!--        <div class="swiper-slide"><img src="/images/03.jpg" alt=""></div>-->
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
</div>

<footer>底部内容</footer>
<script>
    // 2秒回动态返回数据，进行渲染
    // swiper 初始化过早
    setTimeout(()=>{
        let list = ["/images/01.jpg","/images/02.jpg","/images/03.jpg"];
        let newList = list.map(item=>`<div class="swiper-slide"><img src="${item}" alt=""></div>`)

        let wrapper = document.querySelector(".swiper-wrapper")
        wrapper.innerHTML = newList.join('')

        inti()
    },2000)


    function inti() {
        // 初始化 swiper
        new Swiper(".swiper", {

            // direction: 'vertical', // 垂直切换选项

            loop: true, // 循环模式选项

            // 如果需要分页器
            pagination: {
                el: '.swiper-pagination',
            },

            // 如果需要前进后退按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },

            // 如果需要滚动条
            // scrollbar: {
            //     el: '.swiper-scrollbar',
            // },

            //自动轮播
            autoplay: {
                delay: 2500,
                disableOnInteraction: false,
            },
        })
    }
</script>
</body>
</html>